using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class HumanController : MonoBehaviour
{
    // Update is called once per frame
    public PlayerCharacter player;
    public Transform cam;

    public float turnSmoothTime = 0.1f;
    float turnSmoothVel;

    void Update()
    {
        float x = Input.GetAxisRaw("Horizontal");
        float z = Input.GetAxisRaw("Vertical");
        Vector3 dir = new Vector3(x, 0, z).normalized;

        if (dir.magnitude >= 0.1f)
        {
            float targetAngle = Mathf.Atan2(dir.x, dir.z) * Mathf.Rad2Deg + cam.eulerAngles.y;
            float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, 
                targetAngle, ref turnSmoothVel, turnSmoothTime);
            transform.rotation = Quaternion.Euler(0f, angle, 0f);

            Vector3 moveDir = Quaternion.Euler(0f, targetAngle, 0f) * Vector3.forward;
            player.Move(moveDir.normalized);
        }
        else
        {
            player.Move(Vector3.zero);
        }
        // controller.Move(dir * moveSpeed);
        // player.Move(x, z);
        // player.Move(player.transform.right * x + player.transform.forward * z);

        if (Input.GetMouseButtonDown(0))
        {
            player.airCannonWeapon.Fire();
            player.SetWindPower(player.airCannonWeapon.energyCost);
        }

        if (Input.GetMouseButtonDown(1))
        {
            player.airCannonWeapon.SwitchCannonLevel();
        }

        if (Input.GetButtonDown("Jump"))
        {
            player.Jump();
        }
    }
}